import 'package:flower_flutter/constant/constant.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

/// 基础组件
class BasicWidgetPage extends StatefulWidget {
  @override
  _BasicWidgetPage createState() => _BasicWidgetPage();
}

class _BasicWidgetPage extends State<BasicWidgetPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: new Text('基础Widget'),
      ),
      body: ContentPage(),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
    );
  }
}

class ContentPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _ContentPageState();
}

class _ContentPageState extends State<ContentPage> {
  var _radioGroupValue = '语文';
  var _checkValue = false;
  double _sliderValue = 0;
  var _switchValue = false;

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Container(
            alignment: Alignment.center,
            child: Column(children: [
              ///Flutter 1.22版本新增了3个按钮，TextButton、OutlinedButton、ElevatedButton，
              ///虽然以前的Button已经废弃，建议使用新的Button。
              ElevatedButton(
                  onPressed: () => {print("click ElevatedButton")},
                  style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(Colors.amberAccent),
                      shape: MaterialStateProperty.all(StadiumBorder())),
                  child: Text("ElevatedButton")),
              Divider(),
              TextButton(onPressed: () => {print("click TextButton")}, child: Text("TextButton")),
              Divider(),
              OutlinedButton(
                onPressed: () => {print("OutlinedButton")},
                child: Text('OutlinedButton'),
              ),
              Divider(color: Color(0xff333333), height: 10),
              ElevatedButton(
                  style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.grey)
                      ,shape: MaterialStateProperty.all(StadiumBorder())),
                  onPressed: () => {print("click FlatButton")},
                  child: Row(mainAxisSize: MainAxisSize.min, children: [
                    Icon(Icons.favorite, color: Colors.red),
                    Text("喜欢作者", style: TextStyle(color: Colors.white))
                  ])),
              Divider(),
              Padding(
                padding: EdgeInsets.all(15),
                child: RichText(
                    textAlign: TextAlign.start,
                    text: TextSpan(style: DefaultTextStyle.of(context).style, children: [
                      TextSpan(text: '2月3日，山东青岛', style: TextStyle(color: Colors.red)),
                      TextSpan(text: '，', style: TextStyle(color: Colors.blue)),
                      TextSpan(text: Constant.text)
                    ])),
              ),
              Divider(),
              RichText(
                  text: TextSpan(style: DefaultTextStyle.of(context).style, children: [
                TextSpan(text: '登陆即视为同意'),
                TextSpan(
                    text: '《xx服务协议》',
                    style: TextStyle(color: Colors.red),
                    recognizer: TapGestureRecognizer()..onTap = () {})
              ])),
              Divider(),
              Container(
                width: double.infinity,
                child: CheckboxListTile(
                  activeColor: Colors.red,
                  checkColor: Colors.white,
                  controlAffinity: ListTileControlAffinity.leading,
                  title: Text('是否同意协议'),
                  value: _checkValue,
                  onChanged: (value) {
                    setState(() {
                      _checkValue = value;
                    });
                  },
                ),
              ),
              Text('滑动条值：$_sliderValue'),
              Slider(
                  value: _sliderValue,
                  divisions: 100,
                  activeColor: Colors.blue,
                  inactiveColor: Colors.red,
                  label: '$_sliderValue',
                  onChanged: (value) {
                    setState(() {
                      _sliderValue = value;
                    });
                  }),
              Divider(),
              SwitchListTile(
                  title: Text('是否允许4G下载'),
                  value: _switchValue,
                  onChanged: (value) {
                    setState(() {
                      _switchValue = value;
                    });
                  }),
              Divider(),
              CupertinoSwitch(
                  value: _switchValue,
                  onChanged: (value) {
                    setState(() {
                      _switchValue = value;
                    });
                  }),
              Divider(),
              CircularProgressIndicator(
                backgroundColor: Color(0xffffffff),
              ),
              Divider(),
              CupertinoActivityIndicator(
                radius: 30,
              ),
              Divider(),
              Container(
                  height: 300,
                  width: 300,
                  color: Colors.blue,
                  alignment: Alignment.center,
                  child: AspectRatio(aspectRatio: 2 / 1, child: Container(color: Colors.red))),
              Divider(),
              Row(children: [
                Container(color: Colors.blue, height: 50, width: 100),
                Expanded(child: Container(color: Colors.red, height: 50)),
                Container(color: Colors.blue, height: 50, width: 100)
              ])
            ])));
  }
}
